/* sdlfunc.c contains functions heavily related to sdl */

#include "sdlfunc.hxx"

Uint32 TimeLeft(void)
{
    static Uint32 next_time = 0;
    Uint32 now, ret = 0;
    now = SDL_GetTicks();
    if (next_time <= now)
	{
        next_time = now + TICK_INTERVAL;
        return(ret);
    }
    ret = next_time - now;
    return(ret);
}

unsigned int initEnv(char * window_title, unsigned int xmax, unsigned int ymax, unsigned int bpp, Uint32 flags)
{
	//scro.picFile = new char [strlen(scro.execPath) + 255];
	unsigned int ret = 1;
	
	/* Initialize the SDL library */
	if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) < 0) 
	{
    	//logger.log(2, "couldn't init SDL!!\n");
		ret = 0;
	}
 
	/* Clean up on exit */
	//atexit(SDL_Quit);

	//sprintf(scro.picFile, "%s/scro.png", scro.execPath);
	
	//scro.iconPic = IMG_Load(scro.picFile);
	
	//SDL_WM_SetIcon(scro.iconPic, NULL);
	
//	screen = SDL_SetVideoMode(scro.settings.x, scro.settings.y, scro.settings.bpp, scro.settings.flags);
	screen = SDL_SetVideoMode(xmax, ymax, bpp, flags);
	if (screen == NULL) 
	{
		//logger.log(2, "couldn't set video to %dx%dx%d!!", scro.settings.x, scro.settings.y, scro.settings.bpp);
		ret = 0;
	}
	
	SDL_WM_SetCaption(window_title, window_title);
	SDL_EnableUNICODE(1);
    SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);


	//SDL_ShowCursor(SDL_DISABLE);
	return ret;
}

